package batframework.mvc.action;



import java.io.File;

import batframework.code.util.IoUtils;
import batframework.code.util.StringUtils;
import batframework.log.Logger;
import batframework.mvc.conf.MvcApplicationConfing;



public class ActionMapping
{		
	private final static Logger log = Logger.getLogger(ActionMapping.class);
	
	private String path;
	
	private String type;
	
	public ActionMapping(String requestPath,String reuqestMethod)
	{
		log.debug("request : "+reuqestMethod +" : "+requestPath);
		this.path = requestPath.substring(1);
		this.type = reuqestMethod;
		getAction();
		
	}

	public ActionMapping()
	{
		// TODO Auto-generated constructor stub
	}

	public ActionHandler getAction()
	{
		MvcApplicationConfing conf = MvcApplicationConfing.getConf();
		
		if(StringUtils.isEmpty(path))
		{
			ActionHandler action = new ActionHandler();
			action.setType(type);
			return null;
		}
		else
		{
			String[] paths = path.split("/");
			for (String path : paths)
			{
				String controller = conf.getController(path);
				if(!IoUtils.fileExists(controller))
				{
					
				}
				else
				{
					
				}
			}
		}
		
		return null;
	}
	
	private ActionHandler findAction(String controller,String method)
	{
		MvcApplicationConfing conf = MvcApplicationConfing.getConf();
		/*StringBuilder sb = new StringBuilder();

		sb.append("/");
		sb.append(StringUtils.firstToUpperCase(controller));
		sb.append("Controller.class");
		String classpath = sb.toString();
		if(!FileUtils.isExists(classpath))
			return null;
		try
		{
			Class<?> controllerClass = Class.forName("");
			Action action = new Action();
			action.setControllerClass(controllerClass);
			if (controllerClass != null)
			{
				Method m= controllerClass.getMethod(method);
				action.setMethod(m);
				if(m != null)
				{
				
				}
			}
			
		
			
		} catch (ClassNotFoundException e)
		{
			return null;
		} catch (NoSuchMethodException e)
		{
			return null;
		} catch (SecurityException e)
		{
			return null;
		}*/
		return null;
	}
	
	public void urlResolve(String[] urlMapping)
	{
		int len = urlMapping.length;
		if(len == 0)
		{
			//default
			return;
		}
		String first = urlMapping[1];
		boolean exists = IoUtils.fileExists(first);
		if(!exists)
		{
			String[] paths = path.split("/");
			
		}
	}
	
	public static void main(String[] args)
	{
		long s1 = System.currentTimeMillis();
		for (int i = 0; i < 10000; i++)
		{
			IoUtils.fileExists("F:\\迅雷下载\\【6v电影www.dy131.com】来历不明HD国语中字1280版.rmvb");
		}
		long s2 = System.currentTimeMillis();
		System.out.println(s2 - s1);
	}
}
